<%@page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 101 Template</title>
<t:base type="jquery,easyui,jqueryui-sortable,tools"></t:base>
<link href="plug-in/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src="/plug-in/bootstrap/js/bootstrap.min.js"></script>
<style>
.margin-top {
	margin-top: 5px
}

.padding {
	padding: 5px
}
</style>


<script type="text/javascript">
	var editIndex = undefined;
	function endEditing() {
		if (editIndex == undefined) {
			return true
		}
		if ($('#dg').datagrid('validateRow', editIndex)) {
            var ed = $('#dg').datagrid('getEditor', {index:editIndex,field:'type'});
            var typeName = $(ed.target).combobox('getText');
            $('#dg').datagrid('getRows')[editIndex]['typeName'] = typeName;
            $('#dg').datagrid('endEdit', editIndex);
            editIndex = undefined;
			return true;
		} else {
			return false;
		}
	}
	function onClickRow(index) {
		if (editIndex != index) {
			if (endEditing()) {
				$('#dg').datagrid('selectRow', index).datagrid('beginEdit',index);
				editIndex = index;
			} else {
				$('#dg').datagrid('selectRow', editIndex);
			}
		}
	}
	function append() {
		if (endEditing()) {
			$('#dg').datagrid('appendRow', {});
			editIndex = $('#dg').datagrid('getRows').length - 1;
			$('#dg').datagrid('selectRow', editIndex).datagrid('beginEdit',
					editIndex);
		}
	}
	function removeit() {
		if (editIndex == undefined) {
			return
		}
		$('#dg').datagrid('cancelEdit', editIndex).datagrid('deleteRow',editIndex);
		editIndex = undefined;
	}
	function accept() {
		if (endEditing()) {
			$('#dg').datagrid('acceptChanges');
		}
	}
	function reject() {
		$('#dg').datagrid('rejectChanges');
		editIndex = undefined;
	}
	function getChanges() {
		var rows = $('#dg').datagrid('getChanges');
		alert(rows.length + ' rows are changed!');
	}
	
	
	function addLine() {
		debugger;
		append();
	}

	function delLine() { 
		removeit();
	}

</script>


</head>
<body>
	<div class="list-group">
		<div class="list-group-item margin-top">
			<span>元数据编码</span> <input type="text" class="form-control"><span>元数据名称</span> <input
				type="text" class="form-control"> <span>引用数据库表</span><input type="text"
				class="form-control">
		</div>
		<div class="list-group-item datagrid-toolbar padding">
			<button type="button" class="btn btn-default" onclick="addLine()">增行</button>
			<button type="button" class="btn btn-default" onclick="delLine()">删行</button>
		</div>
	</div>

	<table id="dg" class="easyui-datagrid" style="width: 880px; height: 380px;"
		data-options="singleSelect: true,onClickRow: onClickRow">
		<thead>
			<tr>
				<th data-options="field:'code',width:80,editor:'text',align:'center'">编码</th>
				<th data-options="field:'name',width:100,editor:'text',align:'center'">名称</th>
				<th
					data-options="field:'type',width:100,
					 formatter:function(value,row){
                            return row.typeName;
                     },
                    editor:{
                        type:'combobox',
                        options:{
                            valueField:'id',
                            textField:'name',
                            method:'get',
                             url:'${pageContext.request.contextPath}/metadataController.do?getAllDataType',
                            required:true
                        }
                    },align:'center'">类型</th>
				<th
					data-options="field:'length',width:100,align:'center',editor:{type:'numberbox'},align:'center'">长度</th>
				<th data-options="field:'refColumn',width:100,editor:'text',align:'center'">引用列</th>
				<th
					data-options="field:'refMd',width:100,
                        editor:{
                            type:'combobox',
                            options:{
                                valueField:'id',
                                textField:'name',
                                method:'get',
                                url:'${pageContext.request.contextPath}/metadataController.do?getAllMetadata',
                            }
                        },align:'center'">引用元数据</th>
			</tr>
		</thead>
	</table>

</body>
</html>